package com.cms.cmsbackend.controller;

import com.cms.cmsbackend.pojo.Category;
import com.cms.cmsbackend.pojo.Link;
import com.cms.cmsbackend.service.CategoryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
@Api(tags="栏目管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping("/add")
    @ApiOperation("栏目新增")
    public String add(Category category){
        categoryService.save(category);
        return "数据新增成功";
    }
    @GetMapping("/findByPage")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "size",value = "页面大小",required = true)
    })
    public PageInfo findByPage(int page,int size){
       return categoryService.selectByPage(page,size);
    }
    @GetMapping("/delete")
    @ApiImplicitParam(name = "id",value = "编号",required = true)
    @ApiOperation("删除")
    public String delete(int id){
        categoryService.remove(id);
        return "删除成功";
    }
    @GetMapping("/batchDelete")
    @ApiImplicitParam(name = "ids",value = "批量编号",required = true)
    @ApiOperation("批量删除")
    public  String batchDelete(int[] ids){
        for(int id:ids){
            categoryService.remove(id);
        }
        return "删除成功";
    }
    @GetMapping("/findById")
    @ApiOperation("根据id查询")
    @ApiImplicitParam(name="id",value ="栏目编号",required = true)
    public Category findById(int id){
       return categoryService.select(id);
    }
    public String update(Category category){

        categoryService.update(category);
        return "数据更新成功";
    }
}
